//package com.lagou.edu.config;
//
//import com.lagou.edu.annotations.C;
//import org.springframework.beans.BeansException;
//import org.springframework.beans.factory.config.BeanDefinition;
//import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
//import org.springframework.beans.factory.support.BeanDefinitionRegistry;
//import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
//import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.ScannedGenericBeanDefinition;
//import org.springframework.core.type.AnnotationMetadata;
//import org.springframework.core.type.filter.AnnotationTypeFilter;
//
//import java.util.Set;
//
//import static java.lang.Class.forName;
//
///**
// * 自定义的BeanDefine
// */
//@Configuration
//public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
//
//    private static final String BASE_PACKAGE="com.lagou.edu";
//
//    @Override
//    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
//        ClassPathScanningCandidateComponentProvider componentProvider =
//                new ClassPathScanningCandidateComponentProvider(false);
//        componentProvider.addIncludeFilter(new AnnotationTypeFilter(C.class));
//        Set<BeanDefinition> candidateComponents = componentProvider.findCandidateComponents(BASE_PACKAGE);
//        for (BeanDefinition definition : candidateComponents) {
//            String registerName = definition.getBeanClassName();
//            AnnotationMetadata metadata = ((ScannedGenericBeanDefinition) definition).getMetadata();
//            for (String type : metadata.getAnnotationTypes()) {
//                try {
//                    if (forName(type).isAnnotationPresent(C.class)) {
//                        String value = metadata.getAnnotationAttributes(type).get("value").toString();
//                        if (!"".equals(value.trim())) {
//                            registerName = value;
//                            break;
//                        }
//                    }
//                } catch (ClassNotFoundException e) {
//                    e.printStackTrace();
//                }
//            }
//            beanDefinitionRegistry.registerBeanDefinition(registerName, definition);
//        }
//
//    }
//
//    @Override
//    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
//
//    }
//
//}
